package com.qf.lanzhou.shop.api.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.ServletContext;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
import javax.servlet.http.HttpSessionEvent;
import javax.servlet.http.HttpSessionListener;

/**
 * @Author jian
 * @Date 2021/1/13 21:03
 * @JDK 1.8
 * @Version 1.0
 */

public class Mylistener implements HttpSessionListener, ServletContextListener {


    //application对象初始化
    @Override
    public void contextInitialized(ServletContextEvent sce) {
        //获取application对象
        ServletContext sc=sce.getServletContext();
        //在application对象存储变量统计在线人数
        sc.setAttribute("count",0);
    }



    /*创建*/
    /*@Override
    public void sessionCreated(HttpSessionEvent se) {

        System.out.println("jjj");
        //获取ServletContext对象
        ServletContext sc=se.getSession().getServletContext();
        //获取count
        int count= (int) sc.getAttribute("count");
        count=count+1;
        //存储
        sc.setAttribute("count",count);

    }*/

//    销毁
/*    @Override
    public void sessionDestroyed(HttpSessionEvent se) {
        //获取ServletContext对象
        ServletContext sc=se.getSession().getServletContext();
        //获取count
        int count= (int) sc.getAttribute("count");
        count=count-1;
        //存储
        sc.setAttribute("count",count);
    }*/

}
